<?php
 $yhendus=new mysqli("localhost", "if13", "ifikad", "if13_ulpst_p");
 if(isSet($_REQUEST["valjastamine_id"])){
 $kask=$yhendus->prepare("UPDATE mikrobussivedu SET arveseisund=1 WHERE id=?");
 $kask->bind_param("i", $_REQUEST["valjastamine_id"]);
 $kask->execute();
 }
?>
<!doctype html>
<html>
 <head>
 <title>Mikrobussid | Arve väljastamine</title>
 </head>
 <body>
 <h1>Arve väljastamine</h1>
 <table border="1">
 <tr>
	<th>Kliendi nimi</th> 
	<th>Kontakt</th> 
	<th>Sõidetud kilomeetrid</th> 
	<th>Arve saatmine</th> 
</tr>
 <?php
 $kask=$yhendus->prepare("SELECT id, kliendinimi, kontakt, kmarv, arveseisund FROM mikrobussivedu WHERE teeninduseseisnund=2");
 $kask->bind_result($id, $kliendinimi, $kontakt, $kmarv, $arveseisund);
 $kask->execute(); while($kask->fetch()){
 
 echo "<tr>
 <td>$kliendinimi</td>
 <td>$kontakt</td>
 <td>$kmarv</td>
 <td>";
 if($arveseisund==0){
 echo "
	<form action='?'>
			 <input type='hidden' 
			 name='valjastamine_id' value='$id' />
			 <input type='submit' value='Väljasta arve' />
		 </form>";
}
else {
echo "Arve väljastatud";
}
 echo "
		 </td>
</tr>";
 }
 ?>
</table>
 </body>
</html>
<?php
 $yhendus->close();
?>